
function check_login(){
	
	
	var name = $("#name").val();
	var password = $("#password").val();
	if(name == ""){
		layer.alert("用户名不能为空!",
					{
						title:"提示",
						icon:5
					}
				);
		return false;
	}
	if(password == ""){
		layer.alert("密码不能为空!",
					{
						title:"提示",
						icon:5
					}
				);
		return false;
	}
	var wait = layer.load(2);
	$.post(
			"adminLogin",
			{
				loginName:$("#name").val(),
				loginPassword:$("#password").val()
			},
			function(data){
				if(data == "OK"){
					layer.close(wait);
					location.href="adminIndex";
				}else{
					layer.close(wait);
					layer.alert("用户名或密码错误!",
								{
									title:"提示",
									icon:5
								}
							);
				}
			}
			);
}

function btn_add_news(){
	layer.open(
				{
					type:1,
					title:"添加新闻",
					area:['1000px','600px'],
					content:$("#add_news")
				}
			);
}
function btn_add_newsTopic(){
	layer.open(
				{
					type:1,
					title:"添加主题",
					area:"400px",
					content:$("#add_newsTopic")
				}
			);
}
function add_news_submit(){
	var var_title = $("#add_news_news_title").val();
	var var_summary = $("#add_news_news_summary").val();
	var var_content = $("#add_news_news_content").val();
	if(var_title == ""){
		layer.alert("新闻标题不能为空!");
		return;
	}
	if(var_summary == ""){
		layer.alert("新闻摘要不能为空!");
		return;
	}
	if(var_content == ""){
		layer.alert("新闻内容不能为空!");
		return;
	}
	layer.confirm("确定要添加此新闻吗？",
				{
					title:"提示",
					icon:3
				},
				function(){
					var wait = layer.load(3);
					$.post(
							"addNewsinfo",
							{
								topicId:$("#add_news_topic_id").val(),
								newsinfoTitle:$("#add_news_news_title").val(),
								newsinfoSummary:$("#add_news_news_summary").val(),
								newsinfoContent:$("#add_news_news_content").val(),
								newsinfoAuthor:$("#add_news_author").val()
							},
							function(data){
								if(data == "OK"){
									layer.close(wait);
									layer.alert("添加新闻成功!",
											{
												title:"提示",
												icon:6
											},
											function(){
												location.href="adminIndex";
											}
											);
									
								}else{
									layer.close(wait);
									layer.alert("添加新闻失败!",
											{
												title:"提示",
												icon:5
											});
								}
							}
							);
				}
				
			);
}

function add_newsTopic_submit(){
	var var_topic = $("#add_topic_topic_name").val();
	if(var_topic == ""){
		layer.alert("新闻主题不能为空!",
				{
					title:"提示",
					icon:5
				}
				);
		return;
	}
	var wait = layer.load(3);
	$.post(
			"addTopic",
			{topicName:$("#add_topic_topic_name").val()},
			function(data){
				if(data == "OK"){
					layer.close(wait);
					layer.alert("添加主题成功!",
							{
								title:"提示",
								icon:6
							},
							function(){
								location.href="adminIndex";
							}
							);
					
				}else{
					layer.close(wait);
					layer.alert("添加主题失败!",
							{
								title:"提示",
								icon:5
							}
							);
				}
			}
			
			);
	
}

/*
 * 修改新闻
 */
function update_news(id){
	location.href="doEditNews?newsId="+id;
	
}
function edit_news_submit(){
	layer.confirm("确定要修改吗?",
				{
					title:"提示",
					icon:3
				},
				function(){
				    var wait = layer.load(3);
				    $.post(
				    		"editNews",
				    		{
				    			newsId:$("#edit_news_news_id").val(),
				    			topicId:$("#edit_news_topic_id").val(),
				    			newsinfoAuthor:$("#edit_news_news_author").val(),
				    			newsinfoContent:$("#edit_news_news_content").val(),
				    			newsinfoSummary:$("#edit_news_news_summary").val(),
				    			newsinfoTitle:$("#edit_news_news_title").val()
				    		},
				    		function(data){
				    			if(data == "OK"){
				    				layer.close(wait);
				    				layer.alert("修改成功!",
				    						{
				    							title:"提示",
				    							icon:6
				    						},
				    						function(){
				    							location.href="adminIndex";
				    						}
				    						);
				    				
				    			}else{
				    				layer.close(wait);
				    				layer.alert("修改失败!",
				    						{
				    							title:"提示",
				    							icon:5
				    						});
				    			}
				    		}
				    		);
				}
			);
}

function delete_news(id){
	layer.confirm("确定要删除吗?",
				{
					title:"提示",
					icon:3
				},
				function(){
					var wait = layer.load(3);
					$.post(
							"deleteNews",
							{newsId:id},
							function(data){
								if(data == "OK"){
									layer.close(wait);
									layer.alert("删除成功!",
											{
												title:"提示",
												icon:6
											},
											function(){
												location.href="adminIndex";
											});
								}else{
									layer.close(wait);
									layer.alert("删除失败!",
											{
												title:"提示",
												icon:5
											});
								}
							});
				}
				
			);
}

function update_topic(id){
	location.href="toEditTopic?topicId="+id;
}

function edit_topic_submit(){
	layer.confirm("确定要修改主题吗?",
			{
				title:"提示",
				icon:3
			},
			function(){
				var wait = layer.load(3);
				$.post(
						"editTopic",
						{
							topicId:$("#edit_topic_topic_id").val(),
							topicName:$("#edit_topic_topic_name").val()
						},
						function(data){
							if(data == "OK"){
								layer.close(wait);
								layer.alert("修改主题成功!",
										{
											title:"提示",
											icon:6
										},
										function(){
											location.href="doEditTopic";
										});
							}else{
								layer.close(wait);
								layer.alert("修改主题失败!",
										{
											title:"提示",
											icon:5
										});
							}
						});
			});
}
function delete_topic(id){
	layer.confirm("确定要删除吗?",
			{
				title:"提示",
				icon:3
			},
			function(){
				var wait = layer.load(3);
				$.post(
						"deleteTopic",
						{topicId:id},
						function(data){
							if(data == "OK"){
								layer.close(wait);
								layer.alert("删除成功!",
										{
											title:"提示",
											icon:6
										},
										function(){
											location.href="doEditTopic";
										});
							}else{
								layer.close(wait);
								layer.alert("删除失败!请先确定是否有关联新闻？",
										{
											title:"提示",
											icon:5
										});
							}
						});
			}
			
		);
}

function logout(){
	layer.confirm("确定要注销吗?",
			{
				title:"温馨提示",
				icon:3
			},
			function(){
				layer.alert("注销成功!您已下线!",
						{
							title:"温馨提示",
							icon:6
						},
						function(){
							location.href="logout";
						}
						);
				
			});
}